//
//  PhotoScrollView.m
//  结构
//
//  Created by 看着太阳吃烧饼 on 15/7/23.
//  Copyright (c) 2015年 看着太阳吃烧饼. All rights reserved.
//

#import "PhotoScrollView.h"
#import "UIImageView+WebCache.h"
@implementation PhotoScrollView

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _imageView = [[UIImageView alloc] initWithFrame:self.bounds];
        _imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:_imageView];
    }
    self.delegate = self;
    self.maximumZoomScale = 3;
    self.minimumZoomScale = 1;
    UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap)];
        //设置双击 点击触摸板几次
    doubleTap.numberOfTapsRequired = 2;
        //设置触点个数
    doubleTap.numberOfTouchesRequired = 1;
    [self addGestureRecognizer:doubleTap];
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap)];
    [self addGestureRecognizer:singleTap];
        //当双击的时候 屏蔽 单击
    [singleTap requireGestureRecognizerToFail:doubleTap];
    return self;
}

- (void)setImageUrlStr:(NSString *)imageUrlStr {
    _imageUrlStr = imageUrlStr;
    [self setNeedsLayout];
}

- (void)layoutSubviews {
    [_imageView sd_setImageWithURL:[NSURL URLWithString:self.imageUrlStr]];
    
//    self.maximumZoomScale = 3;
//    self.minimumZoomScale = 1;
//    //敲击手势
//    UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap)];
//    //设置双击 点击触摸板几次
//    doubleTap.numberOfTapsRequired = 2;
//    //设置触点个数
//    doubleTap.numberOfTouchesRequired = 1;
//    [self addGestureRecognizer:doubleTap];
//    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap)];
//    [self addGestureRecognizer:singleTap];
//    //当双击的时候 屏蔽 单击
//    [singleTap requireGestureRecognizerToFail:doubleTap];
    
}

- (void)doubleTap {
    if (self.zoomScale == 1) {
        [self setZoomScale:3 animated:YES];
    }else{
        [self setZoomScale:1 animated:YES];
    }
}

- (void)singleTap {
    //设置通知  通知photoViewController执行
    [[NSNotificationCenter defaultCenter]postNotificationName:@"HideNavigationBar" object:nil];
}

- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return _imageView;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
